package cn.stylefeng.guns.sys.modular.sysdistrict.controller;

import cn.stylefeng.guns.core.annotion.BusinessLog;
import cn.stylefeng.guns.core.enums.LogAnnotionOpTypeEnum;
import cn.stylefeng.guns.core.pojo.response.ResponseData;
import cn.stylefeng.guns.core.pojo.response.SuccessResponseData;
import cn.stylefeng.guns.sys.modular.sysdistrict.entity.SysDistrict;
import cn.stylefeng.guns.sys.modular.sysdistrict.model.param.SysDistrictParam;
import cn.stylefeng.guns.sys.modular.sysdistrict.service.SysDistrictService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * sys_district 控制器
 *
 * @author: 刘耀
 * @date: 2021/03/15 20:13
 */
@RestController
public class SysDistrictController {

    @Resource
    private SysDistrictService sysDistrictService;

    /**
     * 分页查询sys_district
     *
     * @author 刘耀
     * @date 2021/03/15 20:13
     */
    @GetMapping("/sysDistrict/page")
    @BusinessLog(title = "sys_district_分页查询", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData page(SysDistrictParam sysDistrictParam) {
        return new SuccessResponseData(sysDistrictService.page(sysDistrictParam));
    }

    /**
     * 获取全部sys_district
     *
     * @author 刘耀
     * @date 2021/03/15 20:13
     */
    @PostMapping("/sysDistrict/list")
    @BusinessLog(title = "sys_district_查询所有", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData list(@RequestBody SysDistrictParam sysDistrictParam) {
        return new SuccessResponseData(sysDistrictService.list(sysDistrictParam));
    }

    /**
     * 查看详情sys_district
     *
     * @author 刘耀
     * @date 2021/03/15 20:13
     */
    @GetMapping("/sysDistrict/detail")
    @BusinessLog(title = "sys_district_查看详情", opType = LogAnnotionOpTypeEnum.DETAIL)
    public ResponseData detail(@Validated(SysDistrictParam.detail.class) SysDistrictParam sysDistrictParam) {
        return new SuccessResponseData(sysDistrictService.detail(sysDistrictParam));
    }

    /**
     * 添加sys_district
     *
     * @author 刘耀
     * @date 2021/03/15 20:13
     */
    @PostMapping("/sysDistrict/add")
    @BusinessLog(title = "sys_district_增加", opType = LogAnnotionOpTypeEnum.ADD)
    public ResponseData add(@RequestBody @Validated(SysDistrictParam.add.class) SysDistrictParam sysDistrictParam) {
        sysDistrictService.add(sysDistrictParam);
        return new SuccessResponseData();
    }

    /**
     * 删除sys_district
     *
     * @author 刘耀
     * @date 2021/03/15 20:13
     */
    @PostMapping("/sysDistrict/delete")
    @BusinessLog(title = "sys_district_删除", opType = LogAnnotionOpTypeEnum.DELETE)
    public ResponseData delete(@RequestBody @Validated(SysDistrictParam.delete.class) SysDistrictParam sysDistrictParam) {
        sysDistrictService.delete(sysDistrictParam);
        return new SuccessResponseData();
    }

    /**
     * 编辑sys_district
     *
     * @author 刘耀
     * @date 2021/03/15 20:13
     */
    @PostMapping("/sysDistrict/edit")
    @BusinessLog(title = "sys_district_编辑", opType = LogAnnotionOpTypeEnum.EDIT)
    public ResponseData edit(@RequestBody @Validated(SysDistrictParam.edit.class) SysDistrictParam sysDistrictParam) {
        sysDistrictService.edit(sysDistrictParam);
        return new SuccessResponseData();
    }

    /**
     * 查询所有省
     *
     * @author 刘耀
     * @date 2021/03/15 20:13
     */
    @PostMapping("/sysDistrict/allProvince")
    @BusinessLog(title = "查询所有省", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData allProvince() {
        return new SuccessResponseData(sysDistrictService.allProvince());
    }

    /**
     * 根据省查市
     *
     * @author 刘耀
     * @date 2021/03/15 20:13
     */
    @PostMapping("/sysDistrict/findCity")
    @BusinessLog(title = "根据省查市", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData findCity(@RequestParam("id") Long provinceId) {
        return new SuccessResponseData(sysDistrictService.findCity(provinceId));
    }

    /**
     * 根据省名称 查询市
     *
     * @author 刘耀
     * @date 2021/03/15 20:13
     */
    @PostMapping("/sysDistrict/findCityByProvinceName")
    @BusinessLog(title = "根据省查市", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData findCityByProvinceName(@RequestParam("province") String province) {
        SysDistrict one = sysDistrictService.getOne(new QueryWrapper<SysDistrict>().lambda().eq(SysDistrict::getDistrictName, province));
        return new SuccessResponseData(sysDistrictService.findCity(one.getDistrictId()));
    }
    /**
     * 根据市查区
     *
     * @author 刘耀
     * @date 2021/03/15 20:13
     */
    @PostMapping("/sysDistrict/findArea")
    @BusinessLog(title = "根据市查区", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData findArea(Long cityId) {
        return new SuccessResponseData(sysDistrictService.findArea(cityId));
    }

    /**
     * 省市区树
     *
     * @author 刘耀
     * @date 2021/03/15 20:13
     */
    @PostMapping("/sysDistrict/areaTree")
    @BusinessLog(title = "省市区树", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData areaTree(@RequestBody(required = false) Long provinceId) {
        return new SuccessResponseData(sysDistrictService.areaTree(provinceId));
    }

}
